﻿@model ForumTopicPageModel
@using Nop.Web.Extensions;
@using Nop.Web.Models.Boards;
@using Nop.Web.Models.Common;
@{
    Layout = "~/Views/Shared/_ColumnsOne.cshtml";

    Html.AddTitleParts(Model.Subject);
}
<script type="text/javascript">
    function handleTopicWatch(context) {
        $('#watch-topic-top').text(context.Text);
        $('#watch-topic-bottom').text(context.Text);
    }
</script>

<div class="container">
    <div class="row">
        <div class="col-md-9">
            @Html.Action("ForumBreadcrumb", new { forumTopicId = Model.Id })
        </div>
     
        <div class="col-md-3">
            @Html.Partial("_SearchBox")
        </div>
    </div>
</div>

<div class="container">
    <div class="row">
        <div class="col-md-12">
            <div class="page forum-topic-page panel panel-default form-panel">
                <div class="panel-heading">              
                    <div class="row">    
                        <div class="col-md-5" >
                            <h3 >
                                @Model.Subject

                            </h3>
                        </div>
                        <div class="col-md-7 pull-text-right" >
                            @if (Model.IsCustomerAllowedToEditTopic)
                            {
                                <a class="btn btn-default" href="@Url.RouteUrl("TopicEdit", new { id = Model.Id })"><i class="fa fa-edit"></i>&nbsp; @T("Forum.EditTopic")</a>
                            }
                            @if (Model.IsCustomerAllowedToDeleteTopic)
                            {
                                <a class="btn btn-default" href="@Url.RouteUrl("TopicDelete", new { id = Model.Id })" onclick="@(String.Format(" return confirm('{0}');", T("common.areyousure").Text))">
                                    <i class="fa fa fa-trash-o"></i>&nbsp; @T("Forum.DeleteTopic")
                                </a>
                            }
                            @if (Model.IsCustomerAllowedToMoveTopic)
                            {
                                 <a class="btn btn-default" href="@Url.RouteUrl("TopicMove", new { id = Model.Id })"><i class="fa fa-mail-forward"></i>&nbsp; @T("Forum.MoveTopic")</a>
                            }
                            <a class="btn btn-default" href="@Url.RouteUrl("PostCreate", new { id = Model.Id })"><i class="fa fa fa-reply"></i>&nbsp; @T("Forum.Reply")</a>
                            @if (Model.IsCustomerAllowedToSubscribe)
                            {
                                <a class="btn btn-default" href="#" id="watch-topic-top"><i class="fa fa-eye"></i>&nbsp; @Model.WatchTopicText</a>
                                <script type="text/javascript">
                                                            $(function () {
                                                                $('#watch-topic-top').click(function () {
                                                                    $.ajax({
                                                                        cache: false,
                                                                        type: 'POST',
                                                                        url: '@Url.RouteUrl("TopicWatch", new { id = Model.Id })',
                                                                        dataType: 'json',
                                                                        success: function (data) {
                                                                            $('#watch-topic-top').text(data.Text);
                                                                        },
                                                                        error: function (xhr, ajaxOptions, thrownError) {
                                                                            alert('Failed to watch');
                                                                        }
                                                                    });
                                                                });
                                                            });
                                </script>
                            }
                        </div>
                    </div>

                        
                </div>
                <div class="panel-body">
                     
                    <div class=" upper">
                        @{
                            var pager = Html.Pager(new PagerModel()
                                                       {
                                                           PageSize = Model.PostsPageSize,
                                                           TotalRecords = Model.PostsTotalRecords,
                                                           PageIndex = Model.PostsPageIndex,
                                                           ShowTotalSummary = false,
                                                           RouteActionName = "TopicSlugPaged",
                                                           UseRouteLinks = true,
                                                           RouteValues = new RouteValues { id = Model.Id, slug = Model.SeName }
                                                       });
                        }
                        @pager
                    </div>

   
                    <div class="posts">
                        @foreach (var post in @Model.ForumPostModels)
                        {
                            Html.RenderPartial("_ForumPost", post);
                            <legend></legend>
     
                        }
                    </div>

                    <div @*class="container"*@>              
                        <div class="row">
                            <div class="col-md-12">
                                <div class="topic-footer">
                                    <div class="topic-options alignright">
                                        <a class="btn btn-default" href="@Url.RouteUrl("PostCreate", new { id = Model.Id })"><i class="fa fa fa-reply"></i>&nbsp; @T("Forum.Reply")</a>
                                    </div>
                                    <div class="pager lower">
                                        @pager
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>
            </div>





        </div>
    </div>
</div>
